<template>
    <div class="friend-link-container">
        <Header></Header>
        <div class="friend-link-container-content">
            <div class="friend-link-content">
                <h2 class="page-title">我的朋友们</h2>
                <div class="link-list">
                    <el-card v-for="(link, index) in friendLinks" :key="index" class="link-card">
                        <div class="link-item">
                            <el-image :src="link.linkCover" class="link-logo" fit="cover"></el-image>
                            <div class="link-info">
                                <h3 class="link-name" @click="openExternalLink(`${link.linkUrl}`)">{{ link.name }}</h3>
                                <p class="link-desc">{{ link.description }}</p>
                            </div>
                        </div>
                    </el-card>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import Header from '../components/header/index.vue';
import { listFrontLink } from '@/api/blog/link';

export default {
    name: 'blog-friend-link',
    components: {
        Header
    },
    data() {
        return {
            friendLinks: []
        }
    },
    methods: {
        getFriendLinks() {
            listFrontLink().then(res => {
                this.friendLinks = res.rows;
            })
        },
        openExternalLink(url) {
            window.open(url, '_blank');
        }
    },
    mounted() {
        this.getFriendLinks()
    }
}
</script>

<style scoped>
.friend-link-container {
    background-color: rgb(241, 242, 245);
    min-height: 100vh;
}

.friend-link-container-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.friend-link-content {
    border-radius: 8px;
    padding: 20px;
}

.page-title {
    text-align: center;
    margin-bottom: 30px;
    color: #333;
    font-size: 24px;
}

.link-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.link-card {
    transition: all 0.3s ease;
}

.link-item {
    display: flex;
    align-items: center;
    padding: 10px;
}

.link-logo {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    margin-right: 15px;
    object-fit: cover;
}

.link-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.link-info {
    flex: 1;
}

.link-name {
    margin: 0 0 8px 0;
    font-size: 18px;
    color: #333;
    cursor: pointer;
}

.link-name:hover {
    color: #409EFF;
}

.link-desc {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: #666;
}

.link-url {
    color: #409EFF;
    text-decoration: none;
    font-size: 14px;
}

.link-url:hover {
    text-decoration: underline;
}
</style>